package org.w515.lab0_backend.converter;

import java.util.List;
import java.util.stream.Collectors;
import org.w515.lab0_backend.dto.ProductCreateDTO;
import org.w515.lab0_backend.entity.Product;
import org.w515.lab0_backend.vo.ProductItemVO;

public final class ProductConverter {
    private ProductConverter() {}

    public static ProductItemVO toItemVO(Product p) {
        if (p == null) return null;
        return new ProductItemVO(
            p.getId(),
            p.getName(),
            p.getVersion(),
            p.getVendor(),
            p.getPackageManager(),
            p.getCreateTime(),
            p.getUpdateTime()
        );
    }

    public static List<ProductItemVO> toItemVOList(List<Product> list) {
        if (list == null || list.isEmpty()) return List.of();
        return list.stream().map(ProductConverter::toItemVO).collect(Collectors.toList());
    }

    public static Product fromCreateDTO(ProductCreateDTO dto) {
        if (dto == null) return null;
        Product product = new Product();
        product.setName(dto.getName());
        product.setVersion(dto.getVersion());
        product.setVendor(dto.getVendor());
        product.setPackageManager(dto.getPackageManager());
        return product;
    }
}